<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>RegRead</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>RegRead</h1>

<p>Reads a value from the registry.</p>

<pre class="Syntax">RegRead, OutputVar, RootKey\SubKey [, ValueName]  <em>; v1.1.21+</em>
RegRead, OutputVar, RootKey, SubKey [, ValueName]</pre>
<h3>Parameters</h3>
<dl>

  <dt>OutputVar</dt>
  <dd><p>The name of the variable in which to store the retrieved value. If the value cannot be retrieved, the variable is made blank and <a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1.</p></dd>

  <dt>RootKey</dt>
  <dd><p>Must be either HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_USER, HKEY_CLASSES_ROOT, or HKEY_CURRENT_CONFIG (or the abbreviations for each of these, such as HKLM). To access a remote registry, prepend the computer name and a colon (or in v1.1.21+, a slash), as in this example: <code>\\workstation01:HKEY_LOCAL_MACHINE</code></p></dd>

  <dt>SubKey</dt>
  <dd><p>The name of the subkey (e.g. Software\SomeApplication).</p></dd>
  
  <dt>RootKey\SubKey <span class="ver">[v1.1.21+]</span></dt>
  <dd><p>If <em>RootKey</em> is followed immediately by a slash (<code>\</code>), <em>RootKey</em> and <em>SubKey</em> are merged into a single parameter.</p></dd>

  <dt>ValueName</dt>
  <dd><p>The  name of the value to retrieve. If omitted, <em>Subkey</em>'s default value will be retrieved, which is the value displayed as &quot;(Default)&quot; by RegEdit. If there is no default value (that is, if RegEdit displays &quot;value not set&quot;), <em>OutputVar</em> is made blank and ErrorLevel is set to 1.</p></dd>

</dl>
<h3>ErrorLevel</h3>
<p><span class="ver">[v1.1.04+]</span> This command is able to throw an exception on failure. For more information, see <a href="Catch.htm#RuntimeErrors">Runtime Errors</a>.</p>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if there was a problem (such as a nonexistent key or value) or 0 otherwise.</p>
<p><a href="../Variables.htm#LastError">A_LastError</a> is set to the result of the operating system's GetLastError() function.</p>
<h3>Remarks</h3>
<p>Currently only the following value types are supported: REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ, REG_DWORD, and REG_BINARY.</p>
<p>REG_DWORD values are always expressed as positive decimal numbers.</p>
<p>When reading a REG_BINARY key the result is a string of hex characters. For example, the REG_BINARY value of 01,a9,ff,77 will be read as the string 01A9FF77.</p>
<p>When reading a REG_MULTI_SZ key, each of the components ends in a linefeed character (`n). If there are no components, <em>OutputVar</em> will be made blank. See <a href="FileSelectFile.htm">FileSelectFile</a> for an example of how to extract the individual components from <em>OutputVar</em>.</p>
<p>REG_BINARY values larger than 64K can only be read in v1.1.10.01 and later.</p>
<p>To retrieve and operate upon multiple registry keys or values, consider using a <a href="LoopReg.htm">registry-loop</a>.</p>
<p>For details about how to access the registry of a remote computer, see the remarks in <a href="LoopReg.htm">registry-loop</a>.</p>
<p>To read and write entries from the 64-bit sections of the registry in a 32-bit script or vice versa, use <a href="SetRegView.htm">SetRegView</a>.</p>

<h3>Related</h3>
<p><a href="RegDelete.htm">RegDelete</a>, <a href="RegWrite.htm">RegWrite</a>, <a href="LoopReg.htm">Registry-loop</a>, <a href="SetRegView.htm">SetRegView</a>, <a href="IniRead.htm">IniRead</a></p>
<h3>Example</h3>
<pre class="NoIndent"><em>; Example: Retrieve the path of the Program Files directory.

; The line below ensures that the path of the 64-bit Program Files
; directory is returned if the OS is 64-bit and the script is not.</em>
<a href="SetRegView.htm">SetRegView</a> 64  <em>; Requires v1.1.08+</em>

RegRead, OutputVar, HKEY_LOCAL_MACHINE<span class="red">,</span> SOFTWARE\Microsoft\Windows\CurrentVersion, ProgramFilesDir
MsgBox, Program files are in: %OutputVar%

<em>; Alternative syntax (requires v1.1.21+):</em>
RegRead, OutputVar, HKEY_LOCAL_MACHINE<span class="red">\</span>SOFTWARE\Microsoft\Windows\CurrentVersion, ProgramFilesDir
MsgBox, Program files are in: %OutputVar%

<em>; Another way to retrieve the path of the Program Files directory:</em>
EnvGet OutputVar, % <a href="../Variables.htm#Is64bitOS">A_Is64bitOS</a> ? "ProgramW6432" : "ProgramFiles"
MsgBox, Program files are in: %OutputVar%
</pre>
<p>&nbsp;</p>
<pre class="NoIndent"><em>; The following example retrieves  the TYPE of a registry value (e.g. REG_SZ or REG_DWORD).</em>
MsgBox % RegKeyType(&quot;HKCU&quot;, &quot;Environment&quot;, &quot;TEMP&quot;)
return

RegKeyType(RootKey, SubKey, ValueName)  <em>; This function returns the type of the specified value.</em>
{
    Loop, %RootKey%, %SubKey%
        if (A_LoopRegName = ValueName)
            return A_LoopRegType
    return &quot;Error&quot;
}</pre>

</body>
</html>
